<?php
class Admin_IndexController extends Controller{
    public $tableName='sp_enterprises';
    //分页演示
   function index(){
        $page = tool('page');
        var_dump($page);

    }
    //获取用户ip
    function getIp(){
        $ip = tool('ip');
        var_dump($ip::getIp());
    }

    //验证码
    function Vcode(){
        require_once getFileUri('verifyCode');
        $Vcode = new verifyCode(188, 132, 4, 5);
        //可修改属性
        $Vcode->bgcolor   = array(255, 330, 20); //验证码背景颜色
        $Vcode->codeColor = array(0, 255, 0); //验证码文本颜色
        $Vcode->fontSize  = 30; //验证码文字大小
        $Vcode->noise     = false; //是否绘制干扰字符
        $Vcode->noiseNumber = 10; //干扰字符数量
        //绘制验证码
       $Vcode->draw();
    }

    //curl演示
    function curlTest(){
       $ch = tool('curl');
        //post 数据
        $res  =$ch->get('http://www.baidu.com');
        //curl 状态
        //返回结果
        echo $res;
    }

    function newMedoo(){
        $page=isset($_GET['page']) ? $_GET['page'] : 1;
        $model = new Model();
        $page_size = 20;
        $pagestr  = getPagestr($model,$this->tableName,['AND'=>['eid[!]'=>0]],$page,$page_size);
        $data = $model->select('sp_enterprises','*',['AND'=>['eid[!]'=>0],'ORDER'=>'eid DESC','LIMIT'=>[($page-1)*$page_size,$page_size]]);
        foreach ($data as $k=>$v){
            $list[$k]['eid']=$v['eid'];
            $list[$k]['ep_name']=$v['ep_name'];
            $list[$k]['address']=$v['ep_addr'];
            $list[$k]['workcode']=$v['work_code'];
        }
        $table = getTable(['ID','公司名', '地址','税号'], $list,['url1','url2']);
        $this->assign('table',$table);
        $this->assign('page',$pagestr);
        $this->display('admin/index/newMedoo.html');
    }


    function test(){
        $page=isset($_GET['page']) ? $_GET['page'] : 1;
        $model = new Model();
        $page_size = 20;
        $pagestr  = getPagestr($model,'sp_project',['AND'=>['id[!]'=>0]],$page,$page_size);
        $data = $model->select('sp_project','*',['AND'=>['id[!]'=>0],'ORDER'=>'id DESC','LIMIT'=>[($page-1)*$page_size,$page_size]]);
        foreach ($data as $k=>$v){
            $list[$k]['eid']=$v['eid'];
            $list[$k]['ep_name']= $model->get('sp_enterprises','ep_name',['AND'=>['eid'=>$v['eid']]]);
            $list[$k]['cti_code']=$v['cti_code'];
            $list[$k]['iso']=$v['iso'];
            $list[$k]['audit_ver']=$v['audit_ver'];
        }
        $table = getTable(['公司ID','公司名', '项目编号','体系短代码','体系标准版本'], $list,['url1','url2']);
        $this->assign('table',$table);
        $this->assign('page',$pagestr);
        $this->display('admin/index/newMedoo.html');

    }

    function listView(){
        require_once getFileUri('from');
        $page=isset($_GET['page']) ? $_GET['page'] : 1;
        $model = new Model();
        $page_size = 20;
        $pagestr  = getPagestr($model,'sp_project',['AND'=>['id[!]'=>0]],$page,$page_size);
        $data = $model->select('sp_project','*',['AND'=>['id[!]'=>0],'ORDER'=>'id DESC','LIMIT'=>[($page-1)*$page_size,$page_size]]);
        foreach ($data as $k=>$v){
            $list[$k]['eid']=$v['eid'];
            $list[$k]['ep_name']= $model->get('sp_enterprises','ep_name',['AND'=>['eid'=>$v['eid']]]);
            $list[$k]['cti_code']=$v['cti_code'];
            $list[$k]['iso']=$v['iso'];
            $list[$k]['audit_ver']=$v['audit_ver'];
        }
        $table = getTable(['公司ID','公司名', '项目编号','体系短代码','体系标准版本'], $list,['url1','url2']);
        $form=new form($_SERVER['PHP_SELF']);
        $form->layout=false;                   //不使用表格布局，大家可以把这句注释掉看结果有何不同
        $name=$form->form_text("ep_name","ep_name","公司名称","ep_name");
        $submit=$form->form_button("","button","button","搜索",'serach()');
        $form_item=array($name,$submit);
        $fromDom=$form->CreateForm($form_item);
        $this->assign('table',$table);
        $this->assign('from',$fromDom);
        $this->assign('page',$pagestr);
        $this->display('admin/index/newMedoo.html');

    }


    function listViewTest(){
        require_once getModelUri('projectModel');
        $model = new projectModel();
        $page=isset($_GET['page']) ? $_GET['page'] : 1;
        $page_size =20;
        $table='sp_project';
        $where['AND'] = ['id[!]'=>0];
        $pages = getPagestr($model,$table,$where,$page,$page_size);
        $where['ORDER'] = 'id DESC';
        $where['LIMIT'] = [($page-1)*$page_size,$page_size];
        $table  =  $model->getList($table,$where);
        $from  =   $model->getSearchForm();
        $this->assign('table',$table);
        $this->assign('from',$from);
        $this->assign('page',$pages);
        $this->display('admin/index/newMedoo.html');
    }


}